/**
 * Created by fupeng on 17/4/10.
 */
var cinemaDetailModel = require('../models/CinemaDetailModel');
var movieDetailModel = require('../models/MovieDetailModel');
var sign = require('../../common/utils/sign.js');
var jsapiTicketController = require('./JsapiTicketController');
var config = require('../../config');

var queryConfig = function (callback, req) {
    var url = req.protocol + '://' + req.host + req.originalUrl; //获取当前url
    var ret = sign(jsapiTicketController.getJsapiTicket(), url);
    console.log(ret);
    callback(ret);
};


module.exports = {
    getCinema:function( req,res){
        cinemaDetailModel.getCinemaDetailInfoModel(req,function(data){
            queryConfig(function (ret) {
                res.render('cinemadetail',{
                    layout: 'sharehome',
                    sign_pkg: ret.jsapi_ticket,
                    appId: config.app.appid,
                    timestamp: ret.timestamp,
                    nonceStr: ret.nonceStr,
                    signature: ret.signature,
                    sdkKey: config.amap.sdkKey,
                    isCollection: data.isCollection,
                    cinemaDetail:data.cinemaDetail
                });
            },req)

        });
    },
    getMovie:function(req,res){
        movieDetailModel.getMovieDetailInfoModel(req, function(data){
            queryConfig(function (ret) {
                res.render('moviedetail',{
                    layout: 'sharehome',
                    sign_pkg: ret.jsapi_ticket,
                    appId: config.app.appid,
                    timestamp: ret.timestamp,
                    nonceStr: ret.nonceStr,
                    signature: ret.signature,
                    sdkKey: config.amap.sdkKey,
                    isCollection: data.isCollection,
                    movie:data.movie
                });
            },req);
        });

    }

}